#ifndef RAND_UTIL_H
#define RAND_UTIL_H

#include <stdlib.h>

namespace RandUtil
{

DATA_TYPE rand0To1();
DATA_TYPE randRange(DATA_TYPE max);
unsigned int randRange(unsigned int max);
DATA_TYPE randGaussian(DATA_TYPE& secondRandValue);

inline DATA_TYPE rand0To1()
{
	return (DATA_TYPE)rand() / RAND_MAX;
}

inline DATA_TYPE randRange(DATA_TYPE max)
{
	return (DATA_TYPE)rand() / RAND_MAX * max;
}

inline unsigned int randRange(unsigned int max)
{
	return rand() % max;
}

inline DATA_TYPE randGaussian(DATA_TYPE& secondRandValue)
{
	DATA_TYPE x0 = rand0To1();
	DATA_TYPE x1 = rand0To1();
	DATA_TYPE firstRandValue = sqrt(-2 * log(x0)) * cos(2 * PI * x1);
	secondRandValue = sqrt(-2 * log(x0)) * sin(2 * PI * x1);
	return firstRandValue;
}

};

#endif